package com.baizhi.controller;

import com.baizhi.entity.Admin;
import com.baizhi.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("back")
public class AdminController {
    @Autowired
    private AdminService adminService;

    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

    @RequestMapping("login")
    public String login(HttpSession session, Admin admin, String validateCode){
        String realCode = ((String) session.getAttribute("realCode"));
        if(realCode.equalsIgnoreCase(validateCode)!=true){
            return "redirect:/back/login.jsp";
        }
        if(adminService.login(admin)){
            session.setAttribute("login",true);
            return "redirect:/back/manager.jsp";
        }else {
            return "redirect:/back/login.jsp";
        }
    }
}
